import React, { PureComponent } from 'react';
import { Form, Input } from 'antd';
import { connect } from 'dva';

class configStructure extends PureComponent {
    constructor(props) {
        super(props);
        this.state = {
            formItemLayout: {
                labelCol: { span: 4 },
                wrapperCol: { span: 16 },
            }
        }
        this.onConfirm = this.onConfirm.bind(this);
    }
    componentDidMount() {
        if (this.props.onLoaded) {
            this.props.onLoaded(this);
        }
    }
    async onConfirm(params = {}) {
        const {form}=this.props;
        form.validateFields((error, values) => {
            if (!error) {
                form.resetFields()
            } else {
                
            }
        });
    }
    render() {
        const { getFieldDecorator } = this.props.form;
        const {
            propss
        } = this.props;
        let fprops = propss.parameters[0].propertys.filter(item => item.type != "reference")//非引用类型
        // debugger
        return (
            <div>
                <Form
                    {...this.state.formItemLayout}
                    labelAlign={'left'}
                >
                    <Form.Item label="id" style={{ display: 'none' }}>
                        {getFieldDecorator('id', {
                            rules: [
                                { required: true, message: '必填' },
                            ],
                            initialValue: propss.id
                        })(
                            <Input placeholder="id" />
                        )}

                    </Form.Item>
                    {
                        fprops.map(item => {
                            return <Form.Item key={item.key} label={item.name}>
                                {getFieldDecorator(item.key, {
                                    rules: [
                                        { required: true, message: '必填' },
                                    ],
                                    initialValue: item.defaultValue
                                })(
                                    <Input placeholder={`请输入构件宽度${item.name}`} />
                                )}

                            </Form.Item>
                        })
                    }

                </Form>

            </div>
        );
    }
}

export default connect(
    ({

    }) => {
        return {};
    },
    dispatch => ({

    })
)(Form.create('configStructure', {

})(configStructure));